﻿using ICSharpCode.AvalonEdit.Rendering;
using System;
using System.Windows.Media;

namespace NFox.Pyeditor.Runtime
{
    class LineColorizer : DocumentColorizingTransformer
    {

        int _line;

        public LineColorizer(int line)
        {
            Line = line;
        }

        public int Line
        {
            get { return _line; }
            set
            {
                if (value < 1)
                    throw new ArgumentOutOfRangeException("value", value, "Line numbers are 1-based.");
                _line = value;
            }
        }

        protected override void ColorizeLine(ICSharpCode.AvalonEdit.Document.DocumentLine line)
        {
            if (!line.IsDeleted && line.LineNumber == _line)
            {
                ChangeLinePart(line.Offset, line.EndOffset, ApplyChanges);
            }
        }

        void ApplyChanges(VisualLineElement element)
        {
            // apply changes here
            element.TextRunProperties.SetBackgroundBrush(Brushes.Yellow);
            element.TextRunProperties.SetForegroundBrush(Brushes.Black);
        }
    }
}
